home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / NDK / NDK_3.1 / Examples1 / PCMCIA / PCMCIA.General < prev    next >
Encoding:
Text File  |  1999-10-27  |  36.3 KB  |  820 lines

  1.  
  2.               A600/A1200 PCMCIA slot
  3.               by Darren M. Greenwald
  4.  
  5.     (c) Copyright 1993-1999  Amiga, Inc.  All Rights Reserved
  6.  
  7.  
  8. PCMCIA
  9. ------
  10.  
  11. PCMCIA stands for "Personal Computer Memory Card International Association". 
  12. The specification for Release 1.0 was first published in August 1990, followed
  13. by the Release 2.0 specification in September 1991.  The Amiga 600 PCMCIA
  14. implementation was also completed around this time in late 1991.  The PCMCIA
  15. specification describes card socket physical and electrical requirements,
  16. software requirements, and an Intel/MS-DOS specific Execute-In-Place format.
  17.  
  18. The PCMCIA Release 2.0 specification was followed by the Socket Services
  19. Interface Specification Release 1.01, published in September 1991.  The Socket
  20. Services specification is an Intel/MS-DOS specific proposal which provides low
  21. level single or multi socket management.
  22.  
  23. A PCMCIA socket provides a total of 68 pins including 26 address lines, 16
  24. data lines, two card detect pins, two Vcc pins, two Vpp pins, various status
  25. pins, a card RESET pin, a WAIT pin, and other pins required for memory access.
  26. A refresh pin is also reserved for use with PSRAM, though not completely
  27. defined in the September 1991 Release 2.0 specification.  Use of 60-pin and
  28. 88-pin Dynamic RAM (DRAM) cards are standardized primarily by EIA/JEDEC and
  29. JEIDA, and are not covered by the PCMCIA standard.
  30.  
  31. PCMCIA cards are available in the Type I format (3.3mm thick), and Type II
  32. format (5.0mm thick).  In both types, connectors, guides, and other factors
  33. are identical.  Either type of card may be used in the A600 and A1200
  34. computers.
  35.  
  36. PCMCIA sockets are designed such that Vcc/Gnd pins connect first when a card
  37. is inserted followed by all other pins except for the two card detect pins
  38. which connect last (the shortest pins).  When a PCMCIA card is inserted, it
  39. first receives power, then other pins connect, and finally the two card detect
  40. pins connect.  Because the two card connect pins are on opposite sides of the
  41. card, a stable connection is assured when both of these pins make contact.
  42.  
  43. The PCMCIA specification defines three memory regions for cards including
  44. common memory, attribute memory, and I/O address space.  In the Amiga 600/1200
  45. design, access to these memory regions is memory mapped by a custom gate
  46. array.
  47.  
  48. Attribute memory is used to store information describing the card, and may
  49. also include configuration registers.  Attribute memory is potentially 64
  50. megabytes in size.  This is because address generation for attribute memory
  51. space is 26 bits wide, plus a REG line.  In actual use though most vendors are
  52. providing only a few bytes of attribute memory, and partial address decoding
  53. to keep costs down.  For some RAM cards (and Flash-ROMS) attribute memory is
  54. not provided at all.
  55.  
  56. Common memory is potentially as large as 64 Megabytes.  It is common memory
  57. space which is used for the contiguous memory provided by SRAM cards,
  58. Flash-ROM cards, ROM cards, etc.  For cards which do not provide attribute
  59. memory, attribute memory accesses are often mapped into common memory space. 
  60. The PCMCIA software specification allows for this behavior.
  61.  
  62. I/O address space is memory mapped in the A600/A1200 systems.  For both
  63. systems, 128K bytes of address space have been reserved for card I/O space. 
  64. In actual use this has not been a limitation.
  65.  
  66. PCMCIA connectors have four (4) pins assigned for status information.  These
  67. are:
  68.  
  69.     WRITE-PROTECT (+WP)
  70.  
  71.     BATTERY VOLTAGE DETECT 1 (BVD1)
  72.  
  73.     BATTERY VOLTAGE DETECT 2 (BVD2)
  74.  
  75.     READY/BUSY (+RDY/-BSY)
  76.  
  77. For I/O cards, the meaning of the BVD1, BVD2, and RDY/BSY pins are
  78. interpreted as:
  79.  
  80.     BVD2 is used for DIGITAL AUDIO (-SPKR)
  81.  
  82.     BVD1 is used for STATUS CHANGE (-STSCHG)
  83.  
  84.     RDY/BSY is used for INTERRUPT REQUEST (-IREQ)
  85.  
  86. PCMCIA digital audio is a simple single-amplitude on-off audio-waveform
  87. intended to drive the host's speaker.  In the A600/A1200, PCMCIA digital-audio
  88. is mixed with Amiga audio output.  PCMCIA digital audio is useful for simple
  89. sound, such as that provided by modems, but is not suitable for high-fidelity
  90. use.
  91.  
  92. BVD1 and BVD2 are used to monitor battery status for battery backed-up SRAM
  93. cards.  The combination of these two bits can be interpreted as "battery is
  94. good", "battery is low", or "battery has failed."  To interpret these pins
  95. correctly, the host must be aware that the card is infact a SRAM card.
  96.  
  97.  
  98.  
  99. PCMCIA METAFORMAT
  100. -----------------
  101.  
  102. The PCMCIA Metaformat, or "Card Information Structure" is a software/hardware
  103. specification for storing identification information on PCMCIA cards.  In
  104. theory, every PCMCIA card identifies itself by providing this information in
  105. attribute memory.  Of course in actual use we find that this applies for I/O
  106. cards, but most memory card vendors are not interested in adding to the cost
  107. of their cards by providing ROM attribute memory.
  108.  
  109. The Metaformat is based on a 'tuple' structure.  A tuple is a simple variable
  110. length structure consisting of one (1) identifier byte, one (1) link byte, and
  111. 0-255 bytes of data.  The tuple link byte tells software how many bytes are
  112. contained with the tuple, or at least how many bytes until the next tuple in a
  113. chain of tuples.  The actual number of valid bytes within a tuple may be less
  114. than the link value for the purpose of reserving space.
  115.  
  116.         TUPLE CODE    1
  117.         TUPLE LINK    1
  118.         TUPLE DATA    0-255 BYTES
  119.  
  120.  
  121. The PCMCIA software specification defines numerous reserved tuple codes, an
  122. example of which is the required CISTPL_DEVICE tuple.  The CISTPL_DEVICE
  123. tuple has a code value of one (1).  It is required that the first tuple of
  124. all PCMCIA cards be a CISTPL_DEVICE tuple.  Contained within this tuple we
  125. have --
  126.  
  127.         DEVICE TYPE    (SRAM, DRAM, I/O, etc.)
  128.  
  129.         DEVICE SPEED    (In Nanoseconds)
  130.  
  131.         DEVICE SIZE    (In units * unit size)
  132.  
  133. A CISTPL_DEVICE tuple can be as little as three bytes, two of which are
  134. required for the tuple code, and link.  For example, some I/O cards may only
  135. include device type, and device speed interpreted as 100ns, 150ns, 200ns, or
  136. 250ns.  It is also possible to specify device speed more accurately using one
  137. more tuple byte.  An additional byte is required to encode device size as 1-32
  138. units of 512 bytes, 2K bytes, 8K bytes, 32K bytes, 128K bytes, 512K bytes, 2M
  139. bytes.  Using this scheme, it is possible to specify sizes as small as 512
  140. bytes, or as large as 64 megabytes.
  141.  
  142. You can see that the PCMCIA specification places a strong emphasis on
  143. minimizing the amount of data required to store the CIS (Card Information
  144. Structure).  This makes sense given that adding attribute memory to a card can
  145. increase its cost.  PCMCIA defines tuples for recording device information,
  146. configurable card information, tuple linking, identification of data
  147. partitions, manufacturer information, etc.
  148.  
  149. We will not cover each of these tuples in this talk beyond noting that the
  150. definition of each tuple is defined in the PCMCIA Release 2.0 specification. 
  151. It is worth mentioning that there are many rules which must be observed when
  152. searching tuple chains, and a considerable amount of system software can be
  153. required to interpret tuple data.  To ease the burden, system software in the
  154. A600/A1200 provides you with some of the high level functions you will need to
  155. read the Card Information Structure of PCMCIA compatable cards.
  156.  
  157.  
  158.  
  159. PCMCIA AND THE AMIGA 600/1200
  160. -----------------------------
  161.  
  162. The Amiga 600 was the first Amiga computer to offer a PCMCIA compatable card
  163. slot.  The PCMCIA slot on the A600/A1200 complies with Release 1.0
  164. requirements, and supports the Extended Bus Cycle (-WAIT), and Card Reset
  165. (+RESET) lines required by Release 2.0.  The A600/A1200 PCMCIA slot is based
  166. on a memory mapped design, making it possible to support Execute-In-Place code
  167. from RAM, ROM, or FLASH-ROM cards.  
  168.  
  169. Internally the A600/A1200 provide PCMCIA slot interfacing via a custom gate
  170. array known as GAYLE.  GAYLE provides a status register, interrupts for status
  171. changes, software control over the Card Reset line, software control over card
  172. Vpp, and other features.
  173.  
  174. Because the A600/A1200 PCMCIA implementation is entirely memory mapped, the
  175. maximum common memory address space is limited to four (4) megabytes.  The
  176. upper half of our eight (8) megabytes of 24-bit expansion space ($600000
  177. through $9FFFFF) has been used for this purpose.  Another 128K of address
  178. space ($A00000 through $A1FFFF) is used for attribute memory, and the next
  179. 128K bytes ($A20000 through $A3FFFF) is used for I/O address space.
  180.  
  181. This means that our 24-bit CPU systems can use common memory for Execute-In-
  182. Place purposes (SYSTEM RAM expansion, and Execute-In-Place code).  The down
  183. side is that our current implementation does not yet provide a paging register
  184. so that addresses greater than 4MB cannot be generated.  While our system
  185. software cannot currently support XIP and bank switching well, the extended
  186. address space will be useful if we want to support large FLASH-ROM cards.  A
  187. paging register is being considered for this purpose in the future.
  188.  
  189. The PCMCIA slot does have some limitations.  It is a 16 bit interface, and
  190. most SRAM/PSRAM cards are 200-250ns requiring GAYLE provide wait-state
  191. generation.  A specification for PCMCIA DMA was not finalized for the Release
  192. 2.0 specification.  We realize that some of you will prefer to use the common
  193. memory space for 32 bit RAM expansion in the A1200, so a credit-card disable
  194. register is provided in GAYLE.  Software modifications have been added to the
  195. latest V39 release which automatically disables the PCMCIA interface when RAM
  196. is present in card memory space (this does however mean that you lose use of
  197. your PCMCIA slot).
  198.  
  199.  
  200.  
  201. OVERVIEW OF A600/A1200 SOFTWARE SERVICES
  202. ----------------------------------------
  203.  
  204. When we designed the A600 PCMCIA software services, our primary concern was to
  205. provide a broad range of functionality, and to do so in a friendy way for the
  206. end user.  This implied we needed to support use of PCMCIA cards as SYSTEM RAM
  207. expansion, XIP software distributed on ROM cards, disk-like format cards,
  208. auto-booting off disk-like formatted cards, and future support for FLASH-ROM
  209. or I/O cards.
  210.  
  211. The A600/A1200 PCMCIA design was completed before the Socket Services
  212. specification was finalized, however we solved many of the issues other
  213. vendors are trying to implement now.  We felt that the end user should be able
  214. to simply plug in a card, and use it without having to configure the card slot
  215. for any particular use.  It may be that the A600 PCMCIA implementation is the
  216. first to offer true "plug-and-play" features.  While the design does not lend
  217. itself well to a multi-slot support (because of the large amount of contiguous
  218. address space required), the user does not have to configure the card slot for
  219. a specific purpose, or turn the machine on/off to insert new cards.
  220.  
  221. The A600/A1200 Kickstart ROM provides low level software services in the form
  222. of a resource.  We reserve the right to modify the GAYLE hardware, so all
  223. GAYLE accesses must be done through this resource.  We also provide a
  224. trackdisk-like device driver so that disk-like formatted cards can be used.
  225.  
  226. The A600/A1200 Kickstart ROM provide --
  227.  
  228.     o card.resource
  229.  
  230.         AutoConfig SRAM/PSRAM cards at boot time as SYSTEM RAM.
  231.  
  232.         Reset-on-removal of cards in use as SYSTEM RAM.
  233.  
  234.         Debounce/reset newly inserted cards.
  235.  
  236.         Hot-insertion/hot-removal/ownership protocol.
  237.  
  238.         Tuple reader function.
  239.  
  240.         CISTPL_DEVICE tuple decode function.
  241.  
  242.         Status change interrupts.
  243.  
  244.         Card Vpp control (5V or 12V).
  245.  
  246.         Card reset control.
  247.  
  248.         Control over hardware reset-on-removal.
  249.  
  250.         Conigure card for I/O interface; enable card digital audio.
  251.  
  252.         Status register access.
  253.  
  254.         High-performance, direct CPU access to card memory space.
  255.  
  256.         Miscellaneous support functions.
  257.  
  258.     o carddisk.device
  259.  
  260.         Trackdisk.device like emulation for disk-like cards.
  261.  
  262.         Hot-insertion/hot-removal recognition, like floppies.
  263.  
  264.         Single partition, variable geometry support.
  265.  
  266.         All block sizes, and error detection schemes defined
  267.         by the PCMCIA 2.0 specification supported.
  268.  
  269.     o strap
  270.  
  271.         Autoboot Amiga formatted cards, if installed like floppy
  272.         disks.
  273.  
  274.         Auto-execution of Amiga formatted Execute-In-Place cards.
  275.  
  276.         Reset-on-removal of active Execute-In-Place cards.
  277.  
  278.         Ability to install device driver software from cards
  279.         which provide Amiga specific device driver code.
  280.  
  281.     o Amiga FileSystem and CrossDOS
  282.  
  283.         Auto-adjust geometry for newly inserted cards.
  284.  
  285.     o PrepCard Utility
  286.  
  287.         Prepares SRAM cards for use as SYSTEM RAM.
  288.  
  289.         Prepares/Formats SRAM cards for use as DISK-LIKE media.
  290.  
  291.         Sizes SRAM cards.  Auto adjust layout of CIS as required
  292.         based on attribute memory characteristics.
  293.  
  294.         Displays card information in a human readable way.
  295.  
  296.         Provides advanced settings options.
  297.  
  298.  
  299.  
  300. OVERVIEW OF THE CARD.RESOURCE MODULE
  301.  
  302. Unlike our standard Amiga expansion slots, the PCMCIA slot is unique in that a
  303. variety of cards may be inserted/removed when power is on.  PCMCIA cards do
  304. not have Amiga specific expansion code, so recognition of PCMCIA cards, and
  305. configuration must be done outside of expansion.library.  The card.resource
  306. module provides the low-level configuration protocol, and support functions
  307. required for the purpose of configuring PCMCIA cards. 
  308.  
  309. Card.resource functions include --
  310.  
  311.     OWNERSHIP FUNCTIONS
  312.  
  313.         OwnCard()
  314.         ReleaseCard()
  315.  
  316.     GAYLE/CARD HARDWARE FUNCTIONS
  317.  
  318.         ReadCardStatus()
  319.         CardResetCard()
  320.         CardProgramVoltage()
  321.         CardResetRemove()
  322.         CardMiscControl()
  323.  
  324.  
  325.     TUPLE SUPPORT FUNCTIONS
  326.  
  327.         CopyTuple()
  328.         DeviceTuple()
  329.         IfAmigaXIP()
  330.  
  331.     FLOW SUPPORT FUNCTIONS
  332.  
  333.         BeginCardAccess()
  334.         EndCardAccess()
  335.  
  336.     MISCELLANEOUS FUNCTIONS
  337.  
  338.         CardInterface()
  339.         GetCardMap()
  340.         CardAccessSpeed()
  341.         CardForceChange()
  342.         CardChangeCount()
  343.  
  344.  
  345. The card.resource module is also responsible for adding SRAM/PSRAM cards as
  346. SYSTEM RAM.  When a SRAM/PSRAM card is inserted at power-up/reset,
  347. card.resource determines if the card is a memory card, and how card size.  If
  348. the card is not being used to store data, card.resource adds the memory to the
  349. system memory list as low-priority fast RAM.  When a card is added as SYSTEM
  350. RAM, the card.resource module is not added to the system list so PCMCIA device
  351. drivers can properly fail to initialize.  
  352.  
  353.  
  354. Most of the card.resource functions require a pointer to a CardHandle
  355. structure defined in card.h/card.i --
  356.  
  357. struct    CardHandle {
  358.     struct Node cah_CardNode;
  359.     struct Interrupt *cah_CardRemoved;
  360.     struct Interrupt *cah_CardInserted;
  361.     struct Interrupt *cah_CardStatus;
  362.     UBYTE    cah_CardFlags;
  363. };
  364.  
  365. struct Node cah_CardNode
  366.  
  367.     Used by the resource so that your handle can be added to a list
  368.     of handles to be notified when a new card is inserted.  A complete
  369.     description of how to fill in this node structure is described
  370.     in the card.resource AUTODOCS included in your DEVCON kit.  Note
  371.     that the priority field of the node structure is used to enqueue
  372.     handles on the notification list maintained by the card.resource
  373.     module.  Valid priorities for 3rd party device drivers have been
  374.     pre-assigned.  Please see the AUTODOCS for details.
  375.  
  376. struct Interrupt *cah_CardRemoved
  377.  
  378.     Used by the resource to call an interrupt routine you provide
  379.     when a card you own is removed.  You must call ReleaseCard()
  380.     to acknowledge that your driver has received the interrupt, and
  381.     will perform no more accesses to card memory.  The card
  382.     interface is disabled by the resource inhibiting writes/reads
  383.     of card memory until you acknowledge removal.
  384.  
  385. struct Interrupt *cah_CardInserted
  386.  
  387.     Used by the resource to call an interrupt routine you provide
  388.     when a card is inserted.  Your driver is the owner until
  389.     you call ReleaseCard().  Usually your driver will signal
  390.     a task, and use the CopyTuple() function to examine the
  391.     card CIS.  If the card is of a type that your driver understands,
  392.     you retain ownership of the card until it is removed, or your
  393.     driver exits.  If the card is of a type your driver does not
  394.     understand, you call ReleaseCard() and the next driver (if any)
  395.     on the notification list is notified by the resource.
  396.  
  397. struct Interrupt *cah_CardStatus
  398.  
  399.     Used by the resource to call an interrupt routine you provide
  400.     when a change in the card status register is noticed.  Status
  401.     changes include changes of:
  402.  
  403.         WRITE PROTECT pin
  404.  
  405.         BATTERY VOLTAGE DETECT 1/STATUS CHANGE pin
  406.  
  407.         BATTERY VOLTAGE DETECT 2/DIGITAL AUDIO pin
  408.  
  409.         READY-BUSY/INTERRUPT REQUEST pin
  410.  
  411.     Status change interrupts are optional.  If you do not provide
  412.     a pointer to an interrupt in the handle structure, you do not
  413.     receive status change interrupts.
  414.  
  415. UBYTE cah_CardFlags
  416.  
  417.     Various flags defined in resources/card.h and resources/card.i
  418.  
  419.  
  420.  
  421. CARD.RESOURCE OWNERSHIP/CONFIGURATION PROTOCOL
  422. ----------------------------------------------
  423.  
  424. Carddisk.device is a good example of how an Amiga PCMCIA device driver should
  425. be constructed.  Carddisk.device uses card.resource functions to register
  426. itself for notification when a new card is inserted.  When notified,
  427. carddisk.device uses the card.resource CopyTuple() function to examine the
  428. Card Information Structure.  If the card contains data stored in disk-like
  429. format, carddisk.device retains ownership of the card until it is removed.
  430.  
  431. Other device drivers will be written in a similar way.  An example would be a
  432. cardmodem.device driver which would attempt to obtain card ownership when
  433. initialized.  Drivers such as this can "hang-around", waiting for an interrupt
  434. when a new card is inserted.  The CIS contains the information needed to
  435. determine if the card is of a type the driver understands, and if not, the
  436. driver releases the card for examination by the next driver on the
  437. notification list.
  438.  
  439. Back in September 1991 it became apparent that the PCMCIA specification was
  440. still evolving, and that the PCMCIA Metaformat was subject to much
  441. interpretation on the part of the card manufacturer.  Therefore it did not
  442. make sense to try to interpret all tuples, for all cards, and all future cards
  443. in system software.  This means that card.resource leaves interpretation of
  444. card CIS up to the individual driver, though a function is provided which
  445. handles all the details of walking tuple chains to find/copy specific tuples. 
  446. Still, even use of this function is not mandatory.  Device drivers may provide
  447. their own CIS examination code if needed to support a non-compliant card.
  448.  
  449. The OwnCard() function (described in more detail in the AUTODOCS available
  450. with your DEVCON kits) provides these useful options --
  451.  
  452.     OwnCard() can be used to 'poll' for a card in the slot.  This is
  453.     useful in cases where you need to try for immediate card ownership,
  454.     but do not wish to "hang-around" if the slot is empty, or in-use. 
  455.     Remember though that when using polling, a card might have just been
  456.     inserted, and might soon be free for use.  If the card slot is not
  457.     available for use (or empty) your CardHandle is NOT enqueued on the
  458.     notification list.
  459.     
  460.     OwnCard() can be used to obtain an interrupt when the card slot is
  461.     free for use, and a card is inserted.  This is useful if your driver
  462.     wishes to "hang-around", and wait without having to poll the
  463.     resource.  Your driver does not have to check the return value from
  464.     OwnCard() as you will take an immediate card inserted interrupt if
  465.     the card is immediately available.  If the card slot is in-use (or
  466.     empty) the insert interrupt will come later, if at all.
  467.  
  468.     OwnCard() can return an immediate result of SUCCESS/FAILURE as well
  469.     as enqueue your handle for subsequent card insertion/removal.  This
  470.     is the default behavior.
  471.  
  472.     OwnCard() can be told to give your driver ownership such that
  473.     the machine will reset if the card is removed while you own the
  474.     card.  This is not recommended for device drivers (support for
  475.     hot-removal is preferrable), but the option is provided for those
  476.     that need it.
  477.     
  478. So there are a couple of ways you can become the owner of the card.  First, a
  479. successful result from OwnCard() means you are the owner.  If a successful
  480. result is returned, your CardHandle structure is enqueued on the notification
  481. list.  The second way is when your driver receives a card inserted interrupt.
  482. OwnCard() lets you use the notification method(s) that suit your needs.  All
  483. GAYLE registers are set to the defaults when you are given ownership of the
  484. card slot, or release ownership with the ReleaseCard() function.  The
  485. defaults are --
  486.  
  487.     o The card interface is enabled
  488.  
  489.     o Digital audio is disabled
  490.  
  491.     o Hardware write-protect is enabled
  492.  
  493.     o Vpp is set to low power 5V
  494.  
  495.     o Reset-on-removal is disabled, unless requested by your
  496.       CardHandle structure.
  497.  
  498.     o Memory access speed is 250ns.
  499.  
  500.     o WRITE-PROTECT, BVD1, and RDY-BSY status change interrupts
  501.       are enabled.
  502.  
  503.  
  504. The ReleaseCard() function is used for three purposes --
  505.  
  506.     To remove your enqueued CardHandle structure so that your driver
  507.     can exit.
  508.     
  509.     To release ownership of the card when the card is not of a type
  510.     that your driver understands.
  511.  
  512.     To acknowledge that a card you own was removed.
  513.  
  514.  
  515. When you own the card in the card slot normally your device driver will need
  516. to check the Card Information Structure before proceeding.  For example, the
  517. carddisk.device driver checks for a CISTPL_DEVICE tuple, a CISTPL_FORMAT
  518. tuple, and a CISTPL_GEOMETRY tuple.  If a CISTPL_FORMAT tuple is found,
  519. carddisk.device examines this tuple to verify that the data on the card is
  520. stored in disk-like format, determine partition size, block size, error
  521. detection method used, etc.  The CISTPL_DEVICE tuple is examined to determine
  522. if the card is writtable (SRAM or DRAM), and if not, carddisk.device allows
  523. reads but not writes.  The CISTPL_GEOMETRY tuple is examined for the purpose
  524. of filling in the disk geometry structure when the disk geometry structure
  525. for the TD_GETGEOMETRY command.
  526.  
  527. If you were writing a modem device driver, you would most likely want to check
  528. for a CISTPL_DEVICE tuple, CISTPL_VERS_1 tuple (describing the product), and
  529. then check for CISTPL_CFIG tuples (describing the card configuration
  530. registers).  During each step your code would be prepared to reject the card
  531. as unknown, and release it with the ReleaseCard() function.
  532.  
  533. The card.resource module provides you with two useful functions for the
  534. purpose of examining the Card Information Structure.  The first function is
  535. CopyTuple(), which scans tuple chains for the tuple you want copied. 
  536. CopyTuple() understands how to follow tuple links, skip odd bytes in attribute
  537. memory, and follows the documented exceptions specified in the PCMCIA Release
  538. 2.0 documentation.  One such exception is that not all cards have a
  539. CISTPL_DEVICE tuple in attribute memory (in some cases it is not even possible
  540. to store this tuple in attribute memory if attribute memory is not provided). 
  541. CopyTuple() deals with this case by looking for a CISTPL_LINKTARGET tuple in
  542. common memory, and if found, follows the tuple chain in common memory.
  543.  
  544. CopyTuple() also follows implied links, explicit links, skips CISTPL_NULL
  545. tuples, and has a provision for finding multiple copies of a tuple.  Another
  546. interesting property of tuples is that the PCMCIA specification allows for
  547. storing read sensitive configuration registers in the body of a tuple. 
  548. CopyTuple() was written to avoid reading such registers by allowing you to
  549. specify how many bytes of tuple data you want copied.
  550.  
  551. Once you have a copy of a tuple, you can then safely examine the contents
  552. without having to worry about where the tuple is stored in the CIS. 
  553. Configuration registers, and the offset of other active registers are defined
  554. by the CIS.
  555.  
  556. Another valuable function provided by the card.resource module is the
  557. DeviceTuple() function which takes a copy of a CISTPL_DEVICE tuple, and
  558. returns device type, device speed, and device size.  DeviceTuple() understands
  559. how to interpret the optional extended device speed byte, how to interpret
  560. short CISTPL_DEVICE tuples, and will return an error if the CISTPL_DEVICE in
  561. invalid, or uses undefined bits/byte-combinations.
  562.  
  563.  
  564. MORE ON HOT-INSERTION/HOT-REMOVAL
  565. ---------------------------------
  566.  
  567. One interesting point to note from the previous sections is that when a card
  568. is removed, the card interface is disabled until the card owner acknowledges
  569. removal.  This means that large data transfer loops do not have to be
  570. interleaved with explicit checks for card removal.  When the interface is
  571. disabled, reads silently return "junk" data, and writes are silently ignored. 
  572.  
  573. The correct procedure is to bracket data transfer loops with the
  574. BeginCardAccess()/EndCardAccess() functions.  If the card is inserted at the
  575. beginning of the transfer, but not at the end, your code can conclude that the
  576. transfer failed, return an error condition, and call ReleaseCard() which
  577. reenables the card interface.  This procedure also protects against writing to
  578. a card inadvertantly if a card is removed, and a new card inserted in the
  579. middle of your transfer loop (a distinct possibility in a busy multi-tasking
  580. Operating System).
  581.  
  582. Most of the functions provided by the card.resource module require you pass in
  583. your CardHandle structure as an argument.  This is used by the resource to
  584. verify that your driver is actually the card owner.  If you were the owner,
  585. but the card has been removed before you have gotten around to calling
  586. ReleaseCard(), relevant functions above will return errors.
  587.  
  588. One hot-insertion/hot-removal safety feature of ReleaseCard() is that you can
  589. safely use this function to remove your CardHandle structure from the
  590. notification list whether or not you are the card owner.  It is possible for a
  591. card to be inserted after you call ReleaseCard(), but before ReleaseCard()
  592. actually removes your CardHandle structure from the notification list.  This
  593. should cause you no problem.  You may take a card inserted interrupt before
  594. your CardHandle is removed, but your handle will be removed, and ownership
  595. released by the time that ReleaseCard() returns to your code.
  596.  
  597.  
  598. MORE USEFUL CARD.RESOURCE FUNCTIONS
  599. -----------------------------------
  600.  
  601. Device drivers should use the GetCardMap() function to obtain pointers to
  602. PCMCIA memory card spaces.  Should we want to move these in the future,
  603. drivers can continue to work as-is unless we go to a non-memory mapped design.
  604.  
  605. Device drivers should use the CardInterface() function to verify that the
  606. GAYLE hardware is present before proceeding.  This gives us the option of
  607. using a different PCMCIA design for which needed software/hardware work
  608. arounds can be published.
  609.  
  610. ReadCardStatus() is used to read the status of the WRITE-PROTECT pin, BVD1/SC
  611. pin, BVD2/DA pin, and RDY-BSY/IRQ pin.
  612.  
  613. CardResetCard() is used to reset configurable cards.  The +RESET line is held
  614. active for >10us.
  615.  
  616. CardProgramVoltage() is used to set Vpp to low-power 5V (the default), 5V,
  617. or 12V.  12V is required for FLASH-ROM programming.
  618.  
  619. CardResetRemove() is used to enable/disable hardware reset on card removal. 
  620. This option is also supported by the OwnCard() function.
  621.  
  622. CardMiscControl() is used to enable DIGITAL AUDIO, and disable GAYLE's
  623. hardware write-protect feature (needed for some I/O cards). As of Kickstart
  624. V39, 3.01, this function can also be used to selectively enable/disable status
  625. change interrupts for changes in BVD1/SC, BVD2/DA, and RDY-BSY/IRQ.  More
  626. about status change interrupts in the next section.
  627.  
  628. The CardChangeCount() function is used by the system STRAP module to poll
  629. for card insertion.  This function has been made public incase you require
  630. it.  The change count is incremented everytime a card is removed, and
  631. everytime a card is successfully inserted.
  632.  
  633. The CardForceChange() function is intended for use by tools, such as PREPCARD
  634. to force devices to give up ownership of the card.  In general it should not
  635. be used by device drivers.
  636.  
  637. The CardAccessSpeed() function is used to set memory access speed (required
  638. for wait-state generation).  The default is 250ns.  
  639.  
  640.  
  641.  
  642. MORE ON CARD.RESOURCE STATUS CHANGE INTERRUPTS
  643. ----------------------------------------------
  644.  
  645.  
  646. GAYLE provides programmable interrupts whenever there is a change in the
  647. WRITE-PROTECT pin, BVD2/DA pin, BVD1/SC pin, or RDY-BSY/IRQ pin.  For example,
  648. carddisk.device uses status change interrupts to note changes in the
  649. WRITE-PROTECT pin, forcing a disk change so that filesystems automatically
  650. send the TD_PROTSTATUS command to obtain the write-protect state.
  651.  
  652. Up through card.resource V37, the resource enabled status change interrupts
  653. for changes in WRITE-PROTECT, BVD1/SC, and RDY-BSY/IRQ.  As of V39 3.01, the
  654. CardMiscControl() function can be used to selectively enable/disable status
  655. change interrupts for BVD2/DA, BVD1/SC, and RDY-BSY/IRQ.  WRITE-PROTECT status
  656. change interrupts are always enabled, and rare.
  657.  
  658. You will note that changes in BVD2/DA are not enabled by default.  This is
  659. because monitoring for changes in BVD2/BVD1 via interrupts is not that useful
  660. since such a tool must also know that card in the slot is an SRAM card. 
  661. Generating interrupts for I/O cards which provide DIGITAL AUDIO is probably
  662. pointless, however should you find some use for monitoring DA changes via
  663. interrupts Kickstart V39 3.01 now provides this feature.
  664.  
  665. The more observant will note that GAYLE generates an interrupt on status
  666. change, not just when a status line goes from the inactive to the active
  667. state.  This is different from normal Amiga hardware which generates
  668. level-mode interrupts, and latches the interrupt until the hardware is
  669. serviced.
  670.  
  671. It turns out that even though PCMCIA specification recommends that card
  672. vendors support both level-mode, and pulsed-mode interrupts, PCMCIA products
  673. will most likely be designed for and tested on Intel based machines (which by
  674. default use positive edge sensitive interrupts).  To work around this, GAYLE
  675. provides positive, and negative edge sensitive interrupts, but the IRQ line
  676. from the card slot is not directly connected to PAULA.  Amiga PCMCIA device
  677. drivers must be prepared for interrupts generated by GAYLE whenever IRQ goes
  678. active, or inactive.  This means that device driver code may need to test a
  679. status register on the PCMCIA card, or if necessary, check the state of the
  680. IRQ line using the ReadCardStatus() function.
  681.  
  682. The card.resource module clears the interrupt on GAYLE when you return from
  683. the status change interrupt, however in retrospect we realized that for some
  684. cards it is preferrable to service GAYLE first followed by the PCMCIA card
  685. hardware.  This capability is now supported in version 39.1 of the
  686. card.resource module, and can be worked around in previous versions of the
  687. resource by using exec/AddIntServer() to install an INTB_PORTS interrupt
  688. server of priority 127 (causing your interrupt server to be enqueued after the
  689. resource's interrupt server).  Within your status change interrupt you would
  690. set a flag(s) indicating what status bits have changed, and then service the
  691. PCMCIA hardware in your interrupt server.
  692.  
  693.  
  694.     ***SPECIAL NOTE***
  695.  
  696.     Interrupt servers of priority 100 or greater must NOT
  697.     terminate the server chain.  Despite previous publication,
  698.     some servers require the ability to cause interrupts by poking
  699.     PAULA.  Such interrupts are not latched, and can be missed if
  700.     the server chain is terminated by higher priority servers.
  701.     Therefore we now reserve interrupt server priorities 100 or
  702.     greater for servers which never terminate the server chain.
  703.  
  704.  
  705. ABOUT CARDDISK.DEVICE
  706. ---------------------
  707.  
  708. Carddisk.device emulates trackdisk.device, though a few trackdisk.device
  709. commands are not supported.  These include --
  710.  
  711.     TD_GETDRIVETYPE for which defined types are meaningless for
  712.     PCMCIA cards.
  713.  
  714.     TD_GETNUMTRACKS is meaningless for PCMCIA cards; use TD_GETGEOMETRY.
  715.  
  716.     TD_RAWREAD and TD_RAWWRITE are not supported; use CMD_READ and
  717.     CMD_WRITE.
  718.  
  719. Carddisk.device supports all block sizes specified by the PCMCIA
  720. specification, though 128 bytes per sector is not supported by the Amiga
  721. FileSystem.  Carddisk.device supports disk-like cards which do not use error
  722. detection (the recommended PCMCIA default), single-byte checksum error
  723. detection, and double-byte CRC error detection.
  724.  
  725. So far we have not seen MS-DOS PCMCIA implementations make use of block sizes
  726. other than the default 512 bytes per block, or use error detection.  For
  727. maximum data portability we suggest using the defaults when preparing cards
  728. with the PREPCARD utility.
  729.  
  730. Carddisk.device does not support the MS-DOS specific pseudo-floppy format,
  731. which does not use PCMCIA tuples to identify disk-like cards.  This could be
  732. supported by writing a disk-loadable driver which has code to interpret
  733. geometry parameters in the MS-DOS boot sector.
  734.  
  735. Carddisk.device mounts itself as device CC0:, priority 3 which is less than
  736. the priority of DF0:, but typically higher than other media.  To save memory,
  737. the filesystem for CC0: is not started until a disk-like card is inserted in
  738. the machine.
  739.  
  740.  
  741. AMIGA EXECUTE-IN-PLACE (XIP) CARDS
  742. ----------------------------------
  743.  
  744. The A600/A1200 support a simple XIP scheme, however remember that XIP software
  745. cannot be removed without causing a machine reset.  Because of this, XIP makes
  746. the most sense for games, or custom applications.  Complete details of how to
  747. implement an XIP card are available in the card.resource AUTODOCS.
  748.  
  749. XIP software is polled for by the system STRAP module at boot time.  On
  750. systems which do not have harddrives, the user may insert XIP software instead
  751. of a floppy disk when prompted by the STRAP screen.  XIP cards take priority
  752. over disk-like media, so XIP cards can be booted on systems with harddrives,
  753. or removable media.
  754.  
  755. One thing you will want to note about XIP software is that XIP code may not
  756. initialize DOS, or use DOS functions.  This is because DOS requires disk-like
  757. media to boot from, and in the case of boot-block games it is often preferred
  758. that DOS not be started.  We do realize that some of you will want the ability
  759. to use DOS functions, so a work-around (kludge) is described in the
  760. card.resource AUTODOCS.
  761.  
  762. Back when we designed the A600 we decided that it is unrealistic to expect 
  763. game developers to write their code to be entirely PC relative.  Of course
  764. this means we cannot move the PCMCIA common memory address in future low-end
  765. machines, but it does allow game developers to use standard compilation
  766. techniques, and LoadSeg() game software into SRAM cards for testing.  CATS has
  767. such a tool, and is making it available in your DEVCON kits.
  768.  
  769. A final point worth mentioning is that the XIP implementation makes it
  770. possible for Amiga specific PCMCIA cards to download software into RAM, or
  771. install software which executes out of PCMCIA ROM.  XIP software can return
  772. control to the STRAP module, giving us the option of booting off harddrive or
  773. floppy-disk after card specific code has been initialized.  This makes it
  774. possible to use the PCMCIA slot for a variety of custom purposes.
  775.  
  776.  
  777. PCMCIA ATTRIBUTE MEMORY
  778. -----------------------
  779.  
  780. Tuples which appear in attribute memory must use even byte addresses only. 
  781. This was done to decrease costs, but it turns out that real way to decrease
  782. cost is not to provide attribute memory at all.  Infact this is what many
  783. SRAM, and FLASH-ROM vendors have decided to do.  Many cards ignore the REG
  784. line, so attribute memory accesses transparently access common memory.  The
  785. PCMCIA specification allows for this behavior, describing the preferred way
  786. to arrange the CIS for cards which do not have attribute memory.
  787.  
  788. Other SRAM cards provide a few bytes of battery backed up attribute memory,
  789. and some decode attribute memory space but return junk data (usually $FF) if
  790. the attribute memory EPROM option is not installed.  We have yet to actually
  791. come across an SRAM card, or FLASH-ROM card which provides ROM attribute
  792. memory.  What this means is that tools are required (like the PREPCARD tool)
  793. which know how size memory cards, and layout the CIS depending on the type of
  794. attribute memory characteristics of the card.
  795.  
  796. The more observant may have noticed that the PCMCIA specification requires the
  797. first tuple of all compliant cards be the CISTPL_DEVICE tuple describing
  798. device type, device speed, and device size.  This is not possible on cards
  799. which decode attribute memory space, but return junk data.  Therefore our
  800. implementation allows for storing the CISTPL_DEVICE tuple in common memory if
  801. it is not possible to write to attribute memory on the card. This work-around
  802. is not mentioned in the PCMCIA Release 2.0 specification, but seems to be a
  803. reasonable one.
  804.  
  805. Another significant problem not addressed by the PCMCIA specification is
  806. mastering requirements for ROM card vendors.  If you have an interest in
  807. distributing software on masked ROM cards, anticipate that you will need to
  808. work closely with the vendor to define your needs.  You will need to make
  809. sure that the ROM vendor understands that the Card Information Structure
  810. must be accurately duplicated, and possibly re-layed out if the ROM vendor's
  811. cards have different attribute memory characteristics than what you provide
  812. as a master.
  813.  
  814. PCMCIA maintains a list of product vendors which can be obtained along with
  815. the PCMCIA specification.  A copy of the PCMCIA specification, and vendor
  816. listing is available through CATS (you must contact CATS to obtain a current
  817. price for the documents).
  818.  
  819.  
  820.